Ext.onReady(function() {


    var tree_root = new Ext.tree.AsyncTreeNode({
        text : '信息录入',
        id : 'root'
    });
    var tree = new Ext.tree.TreePanel({
        border:'0',
        height: 900,
        id:'tree',
        useArrows:true,     //使用箭头
        autoScroll:true,    //自动滚动
        animate:true,       // 动画
        enableDD:false,      //可拖动
        containerScroll: true,
        rootVisible: false,
        root : tree_root,
        autoScroll : true,
        listeners: {
            beforeload: function(node) {
                var openUrl =  'MenuListJson.action'
                node.loader = new Ext.tree.TreeLoader({
                    dataUrl : openUrl
                });
            }
        }
    });





     var accordion = new Ext.Panel({
         region : 'west',
         //id : 'catalog_west-panel',
         title : '功能菜单',
         width : 200,
         split:true,
         collapsible : true,
         //  frame : true,
         html : '功能菜单',
         layout:'fit',
         items: [tree]
     });
     
     var tabPanel = new Ext.TabPanel({
         title: "标签",
         region : 'center',
         enableTabScroll:true,
         frame: true,
         activeTab: 0
     });
     
	var viewport = new Ext.Viewport( {
		layout : 'border',
		region : 'center',
        deferredRender : false,
        items:[accordion,tabPanel,{
        	region : 'north',
            deferredRender : false,
            height:50,
            activeTab : 0,
            frame : true,
            html : "<div style='text-align: center'><label style='text-align: center'><strong>车辆管理系统</strong></label><label style='float: right'><label style='color: red'>"+username+"</label>   您好！欢迎登陆！</label></div>"
        }
        ]
	});
	
	
	 //这里写点击数出发的事件
    tree.on('click', function(node){
        if(node.leaf){
        	addTab(node);
        }
    });
    

    function addTab(node) {
        var index = node.text;
        var isExit=tabPanel.getItem('tab'+node.id);
        if(isExit==null){
        	var tab = tabPanel.add({
                title: index,
                id:'tab'+node.id,
                html: '<iframe id=cat src="'+node.attributes.url+'?access='+node.attributes.access+'" height=100% width=100% frameborder=0 scrolling=auto></iframe>',
                closable: true 
            });
        }else{
        	var tab=isExit;
        }
        tabPanel.setActiveTab(tab); 
    }
    
//    var indexTab = tabPanel.add({
//        title: "车辆信息检索",
//        id:'tab111',
//        html: '<iframe id=cat src="" height=100% width=100% frameborder=0 scrolling=auto></iframe>',
//        closable: true 
//    });
//    tabPanel.setActiveTab(indexTab); 
});